<template>
	<view class="container">
		<!-- 搜索栏 -->
		<view class="search-box">
			<view class="search-input">
				<uni-icons type="search" size="16" color="#666"></uni-icons>
				<input type="text" v-model="searchText" placeholder="搜索订单" />
			</view>
		</view>
		
		<!-- 轮播图 -->
		<swiper class="banner" circular :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in bannerList" :key="index">
				<image :src="item.image" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		
		<!-- 服务类型网格 -->
		<view class="service-grid">
			<view class="grid-item" v-for="(item, index) in serviceTypes" :key="index" @tap="navigateToService(item)">
				<image :src="item.icon" mode="aspectFit"></image>
				<text>{{item.name}}</text>
			</view>
		</view>
		
		<!-- 接单大厅 -->
		<view class="plaza-section">
			<view class="section-header">
				<text class="title">接单大厅</text>
				<text class="more" @tap="viewMore">全部 ></text>
			</view>
			
			<!-- 订单列表 -->
			<view class="order-list">
				<view class="order-item" v-for="(item, index) in orderList" :key="index" @tap="goToDetail(item)">
					<view class="order-header">
						<view class="user-info">
							<image class="avatar" src="/static/avatar.png" mode="aspectFill"></image>
							<text class="nickname">{{item.userName}}</text>
						</view>
						<text class="order-tag">{{item.type}}</text>
					</view>
					<view class="order-content">
						<text class="order-title">{{item.title}}</text>
						<text class="order-desc">{{item.description}}</text>
						<view class="order-footer">
							<text class="price">￥{{item.price}}</text>
							<text class="location">{{item.location}}</text>
							<text class="time">{{item.time || '尽快送达'}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchText: '',
				bannerList: [
					{ image: '/static/banner/banner1.jpg' },
					{ image: '/static/banner/banner2.jpg' },
					{ image: '/static/banner/banner3.jpg' }
				],
				serviceTypes: [
					{ name: '取快递', icon: '/static/icons/express.png', path: '/pages/service/express/index' },
					{ name: '寄快递', icon: '/static/icons/send.png', path: '/pages/service/send/index' },
					{ name: '打印文件', icon: '/static/icons/print.png', path: '/pages/service/print/index' },
					{ name: '帮购物', icon: '/static/icons/shop.png', path: '/pages/service/shop/index' },
					{ name: '叫个跑腿', icon: '/static/icons/run.png', path: '/pages/service/run/index' },
					{ name: '我要转卖', icon: '/static/icons/sale.png', path: '/pages/service/sale/index' },
					{ name: '失物招领', icon: '/static/icons/lost.png', path: '/pages/service/lost/index' },
					{ name: '万能帮帮', icon: '/static/icons/help.png', path: '/pages/service/help/index' }
				],
				orderList: [
					{
						id: 1,
						userName: '张三',
						type: '取快递',
						title: '帮取快递',
						description: '菜鸟驿站有一个快递，求帮忙取一下',
						price: 5,
						location: '菜鸟驿站',
						time: '12:30前',
						status: '待接单',
						contact: '13800138000',
						createTime: '2024-03-20 10:30'
					},
					{
						id: 2,
						userName: '李四',
						type: '买饭',
						title: '帮买午饭',
						description: '一食堂二楼炒饭，要辣椒',
						price: 8,
						location: '一食堂',
						time: '11:30前',
						status: '待接单',
						contact: '13800138001',
						createTime: '2024-03-20 10:00'
					}
				]
			}
		},
		methods: {
			navigateToService(item) {
				uni.navigateTo({
					url: item.path
				})
			},
			viewMore() {
				uni.switchTab({
					url: '/pages/hall/index'
				})
			},
			goToDetail(item) {
				// 将订单信息转为字符串
				const orderInfo = encodeURIComponent(JSON.stringify(item))
				uni.navigateTo({
					url: `/pages/order-detail/index?orderInfo=${orderInfo}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		background-color: $background-color;
	}

	.search-box {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 100;
		padding: 20rpx;
		background-color: #fff;
		
		.search-input {
			display: flex;
			align-items: center;
			background-color: #f5f5f5;
			padding: 10rpx 20rpx;
			border-radius: 30rpx;
			
			input {
				flex: 1;
				margin-left: 10rpx;
				font-size: 28rpx;
			}
		}
	}

	.banner {
		margin-top: 90rpx;
		height: 300rpx;
		
		image {
			width: 100%;
			height: 100%;
		}
	}

	.service-grid {
		background-color: #fff;
		padding: 20rpx;
		display: flex;
		flex-wrap: wrap;
		
		.grid-item {
			width: 25%;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 20rpx 0;
			
			image {
				width: 80rpx;
				height: 80rpx;
				margin-bottom: 10rpx;
			}
			
			text {
				font-size: 24rpx;
				color: $text-color;
			}
		}
	}

	.plaza-section {
		margin-top: 20rpx;
		background-color: #fff;
		padding: 20rpx;
		
		.section-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;
			
			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: $text-color;
			}
			
			.more {
				font-size: 24rpx;
				color: $text-color-grey;
			}
		}
	}

	.order-list {
		.order-item {
			border-bottom: 1rpx solid $border-color;
			padding: 20rpx 0;
			
			&:last-child {
				border-bottom: none;
			}
			
			.order-header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;
				
				.user-info {
					display: flex;
					align-items: center;
					
					.avatar {
						width: 60rpx;
						height: 60rpx;
						border-radius: 30rpx;
						margin-right: 10rpx;
					}
					
					.nickname {
						font-size: 28rpx;
						color: $text-color;
					}
				}
				
				.order-tag {
					font-size: 24rpx;
					color: $theme-color;
					background-color: rgba($theme-color, 0.1);
					padding: 4rpx 12rpx;
					border-radius: 4rpx;
				}
			}
			
			.order-content {
				.order-title {
					font-size: 32rpx;
					color: $text-color;
					margin-bottom: 10rpx;
					display: block;
				}
				
				.order-desc {
					font-size: 28rpx;
					color: $text-color-grey;
					margin-bottom: 20rpx;
					display: block;
				}
				
				.order-footer {
					display: flex;
					justify-content: space-between;
					align-items: center;
					
					.price {
						color: #ff5500;
						font-size: 36rpx;
						font-weight: bold;
					}
					
					.location, .time {
						font-size: 24rpx;
						color: $text-color-grey;
					}
				}
			}
		}
	}
</style>
